
package Graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import javax.swing.JPanel;

/**
 *
 * @author mhfowler
 */
class DrawingPanel extends JPanel {

    List<MyRectangle> recs;
    int x;
    int y;
    int speedx;
    int speedy;
    int count;
    Color col;
    int a;
    int v1;
    int v2;
    int v3;


public DrawingPanel(int a, int b, int sx, int sy) {
    super();
    java.awt.Dimension size = new java.awt.Dimension(500, 500);
    this.setPreferredSize(size);
    this.setSize(size);
    this.setBackground(java.awt.Color.WHITE);
    recs = new LinkedList<MyRectangle>();
    speedx = sx;
    speedy = sy;
    col = new Color(230,0,0);
    a=1;
}


 @Override
 public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D brush = (Graphics2D) g;
        Random r = new Random();
        double v1 = r.nextDouble();
        double v2 = r.nextDouble();
        double v3 = r.nextDouble();
        col = new Color(0,(int)(255*v2),(int) (255*v3));
        if (count!=(20*a)) {
            x += speedx;
            y += speedy;
            MyRectangle z = new MyRectangle(x,y,100,200, col);
            recs.add(z);
        }
        else  {
            System.out.println("change");
            x  = r.nextInt(400);
            y = r.nextInt(400);
            int signx = 250 - x;
            signx = signx/Math.abs(signx);
            int signy = 250 - y;
            signy = signy/Math.abs(signy);
            speedx = 10*signx;
            speedy = 10*signy;
            System.out.println("posx: " + x);
            System.out.println("posy: " + y);
            System.out.println("speedx: " + speedx);
            System.out.println("speedy: " + speedy);
            MyRectangle z = new MyRectangle(x,y,100,200, col);
            recs.add(z);
            a++;
        }
        for (MyRectangle k : recs) {
            k.draw(brush);
        }
        count++;
    }


}
